import { Controller, Get, Post, UseGuards } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { ApiBearerAuth, ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
import { Roles } from '../../../../decorators/roles.decorator';
import { RolesGuard } from '../../../../guards/roles.guard';
import { BoolResDto } from '../../../common/dtos/bool.res.dto';
import { LogAppender } from '../../../log/constants/log.constant';
import { LogService } from '../../../log/services/log.service';
import { Role } from '../../../role/constants/role.constant';

@ApiBearerAuth()
@ApiTags('areas')
@Controller('role/areas')
export class AreaRoleController {
  constructor(private readonly logService: LogService) {}

  @ApiOperation({ summary: '管理权限测试' })
  @ApiOkResponse({ description: '返回测试结果', type: BoolResDto })
  @Roles(Role.manager, Role.admin)
  @UseGuards(AuthGuard(), RolesGuard)
  @Post()
  async testPost(): Promise<BoolResDto> {
    this.logService.info(LogAppender.area, 'Do test to manage role.');

    return { result: true };
  }

  @ApiOperation({ summary: '管理权限和查看权限测试' })
  @ApiOkResponse({ description: '返回测试结果', type: BoolResDto })
  @Roles(Role.viewer, Role.manager, Role.admin)
  @UseGuards(AuthGuard(), RolesGuard)
  @Get()
  async testGet(): Promise<BoolResDto> {
    this.logService.info(LogAppender.area, 'Do test to manage and view roles.');

    return { result: true };
  }
}
